<!DOCTYPE html>
<html lang="zh">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1.0, user-scalable=no">

    
      <link rel="icon" href="/myblog/favicon.png" />
    

    <title>
        
          MySQL安装 - 欢迎来到我的空间
        
    </title>

    <!-- Spectre.css framework -->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/spectre.css/0.5.9/spectre.min.css">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/spectre.css/0.5.9/spectre-exp.min.css">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/spectre.css/0.5.9/spectre-icons.min.css">

    <!-- theme css & js -->
    
<link rel="stylesheet" href="/myblog/css/book.css">

    
<script src="/myblog/js/book.js"></script>


    <!-- tocbot -->
    <script src="https://cdnjs.cloudflare.com/ajax/libs/tocbot/4.4.2/tocbot.min.js"></script>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/tocbot/4.4.2/tocbot.css">
    
    <!-- katex -->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.10.0/katex.min.css">

    
    
<script src="https://cdnjs.cloudflare.com/ajax/libs/zooming/2.1.1/zooming.min.js"></script>
<script>
document.addEventListener('DOMContentLoaded', function () {
    const zooming = new Zooming()
    zooming.listen('.book-content img')
})
</script>

<meta name="generator" content="Hexo 6.3.0"></head>

<body>

<div class="book-container">
  <div class="book-sidebar">
    <div class="book-brand">
  <a href="/myblog/">
    <img src="/myblog/favicon.png">
    <span>欢迎来到我的空间</span>
  </a>
</div>
    <div id="menu" class="book-menu hide">
  <h1 id="主页"><a href="#主页" class="headerlink" title="主页"></a><a href="/myblog">主页</a></h1><h2 id="快速开始"><a href="#快速开始" class="headerlink" title="快速开始"></a><a href="/myblog/2023/02/23/%E5%BF%AB%E9%80%9F%E5%BC%80%E5%A7%8B">快速开始</a></h2><h2 id="数据库"><a href="#数据库" class="headerlink" title="数据库"></a>数据库</h2><ul>
<li><a href="/myblog/2023/02/23/MySQL%E5%AE%89%E8%A3%85">mysql</a></li>
<li><a href="/myblog/2023/02/23/%E5%BF%AB%E9%80%9F%E5%BC%80%E5%A7%8B">redis</a></li>
</ul>
<h2 id="破解小妙招"><a href="#破解小妙招" class="headerlink" title="破解小妙招"></a>破解小妙招</h2><ul>
<li><a href="/myblog/2023/02/24/Navicat%E6%BF%80%E6%B4%BB">Navicat</a></li>
</ul>

</div>


<script src="/myblog/js/book-menu.js"></script>

  </div>

  <div class="sidebar-toggle" onclick="sidebar_toggle()" onmouseover="add_inner()" onmouseleave="remove_inner()">
  <div class="sidebar-toggle-inner"></div>
</div>

<script>
function add_inner() {
  let inner = document.querySelector('.sidebar-toggle-inner')
  inner.classList.add('show')  
}

function remove_inner() {
  let inner = document.querySelector('.sidebar-toggle-inner')
  inner.classList.remove('show')
}

function sidebar_toggle() {
    let sidebar_toggle = document.querySelector('.sidebar-toggle')
    let sidebar = document.querySelector('.book-sidebar')
    let content = document.querySelector('.off-canvas-content')
    if (sidebar_toggle.classList.contains('extend')) { // show
        sidebar_toggle.classList.remove('extend')
        sidebar.classList.remove('hide')
        content.classList.remove('extend')
    }
    else { // hide
        sidebar_toggle.classList.add('extend')
        sidebar.classList.add('hide')
        content.classList.add('extend')
    }
}
</script>

  <div class="off-canvas-content">
    <div class="columns">
      <div class="column col-10 col-lg-12">
        <div class="book-navbar">
          <!-- For Responsive Layout -->

<header class="navbar">
  <section class="navbar-section">
    <a onclick="open_sidebar()">
      <i class="icon icon-menu"></i>
    </a>
  </section>
</header>

        </div>
        <div class="book-content">
          <div class="book-post">
  <p><em>MySQL官网：</em><a target="_blank" rel="noopener" href="https://www.mysql.com/">https://www.mysql.com/</a></p>
<h3 id="Windows"><a href="#Windows" class="headerlink" title="Windows:"></a><strong>Windows:</strong></h3><h5 id="一、下载安装"><a href="#一、下载安装" class="headerlink" title="一、下载安装"></a>一、下载安装</h5><p>1.下载地址</p>
<ul>
<li><p>msi引导安装程序下载地址：<a target="_blank" rel="noopener" href="https://dev.mysql.com/downloads/installer/">https://dev.mysql.com/downloads/installer/</a></p>
</li>
<li><p>二进制包下载地址：<a target="_blank" rel="noopener" href="https://downloads.mysql.com/archives/community/">https://downloads.mysql.com/archives/community/</a></p>
</li>
</ul>
<p>2.这里以二进制包为例，直接解压即可完成安装，这里下载的是版本是<code>mysql-8.0.27-winx64</code></p>
<h5 id="二、配置"><a href="#二、配置" class="headerlink" title="二、配置:"></a><strong>二、配置:</strong></h5><h6 id="1-添加环境变量"><a href="#1-添加环境变量" class="headerlink" title="1.添加环境变量"></a><strong>1.添加环境变量</strong></h6><p>1）进入到<em>环境变量</em>后 ，新建一个系统变量，变量名为<code>MYSQL_HOME</code>,变量值为 MySQL 在电脑上的安装路径，我的是<code>D:\devlopment\mysql-8.0.28-winx64</code>，如下图：</p>
<p><img src="https://ajhond.oss-cn-hangzhou.aliyuncs.com/hexo/202302232215048.png" alt="image-20230223221541665"></p>
<p>2）选中 path ，点击编辑，新建一行，输入<code>%MYSQL_HOME%\bin;</code></p>
<p>到这里就完成了配置，目的是为了方便操作 MySQL。</p>
<h6 id="2-新建配置文件"><a href="#2-新建配置文件" class="headerlink" title="2.新建配置文件"></a><strong>2.新建配置文件</strong></h6><p>1）在 MySQL 的安装目录的根目录下创建一个名为 data 的文件夹，用来存放 MySQL 的数据库信息；</p>
<p>2）在 MySQL 的安装目录的根目录下新建一个文本文件，命名为 my.ini，内容如下：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">[mysqld]</span><br><span class="line">basedir=&quot;D:\devlopment\mysql-8.0.28-winx64&quot;</span><br><span class="line">datadir=&quot;D:\devlopment\mysql-8.0.28-winx64/data&quot;</span><br><span class="line">character-set-server=UTF8MB4</span><br><span class="line"></span><br><span class="line">[client]</span><br><span class="line">default-character-set=UTF8MB4</span><br></pre></td></tr></table></figure>

<p>我的 MySQL 安装目录是<code>D:\devlopment\mysql-8.0.28-winx64</code>，上面的路径根据自己的安装路径进行修改。</p>
<h6 id="3-初始化-MySQL"><a href="#3-初始化-MySQL" class="headerlink" title="3.初始化 MySQL"></a><strong>3.初始化 MySQL</strong></h6><p>使用<strong>管理员权限</strong>打开 cmd，（因为前面配置了环境变量，这里可以直接执行）执行命令</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">mysqld --initialize-insecure</span><br></pre></td></tr></table></figure>

<p>稍等一会儿，查看MySQL根目录下的 data 文件夹，如果有生成文件，则说明初始化成功。</p>
<h6 id="4-注册MySQL服务"><a href="#4-注册MySQL服务" class="headerlink" title="4.注册MySQL服务"></a><strong>4.注册MySQL服务</strong></h6><p>执行<code>mysqld -install</code>，再执行<code>services.msc</code>，就可以在<em>服务</em>中就可以查看到 MySQL 了，</p>
<h6 id="5-启动（停止）MySQL服务"><a href="#5-启动（停止）MySQL服务" class="headerlink" title="5.启动（停止）MySQL服务"></a><strong>5.启动（停止）MySQL服务</strong></h6><p>启动MySQL服务：可以在<em>服务</em>中手动启动，或在cmd中执行<code>net start mysql</code>以启动服务；</p>
<p>停止MySQL服务：在<em>服务</em>中手动关闭， 或在cmd中执行<code>net stop mysql</code>。</p>
<h6 id="6-修改默认账户密码"><a href="#6-修改默认账户密码" class="headerlink" title="6.修改默认账户密码"></a><strong>6.修改默认账户密码</strong></h6><p>在 cmd 中执行命令</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">mysqladmin -u root password 1234，</span><br></pre></td></tr></table></figure>

<p>这里的1234就是默认管理员root（即root账户）的密码了，可以根据自己的情况修改。</p>
<p>至此，你的计算机上已经安装好了MySQL服务，成为一台MySQL服务器。</p>
<h5 id="三、登录MySQL"><a href="#三、登录MySQL" class="headerlink" title="三、登录MySQL"></a><strong>三、登录MySQL</strong></h5><p>首先启动MySQL服务，然后再cmd中执行mysql -uroot -p1234命令，出现下图，则登录成功；</p>
<p>在mysql&gt;后面便可以输入SQL语句来操作数据库了。</p>
<h6 id="登录参数："><a href="#登录参数：" class="headerlink" title="登录参数："></a>登录参数：</h6><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">mysql -u用户名 -p密码 -h要连接的mysql服务器的ip地址（默认127.0.0.1） -P端口号（默认3306）</span><br></pre></td></tr></table></figure>

<p>退出MySQL：</p>
<p>exit</p>
<h5 id="四、卸载MySQL"><a href="#四、卸载MySQL" class="headerlink" title="四、卸载MySQL"></a><strong>四、卸载MySQL</strong></h5><p>1.执行net stop mysql命令停止服务；</p>
<figure class="highlight dockerfile"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">net stop mysql</span><br></pre></td></tr></table></figure>

<p>2.执行mysqld -remove mysql移除MySQL服务；</p>
<figure class="highlight dockerfile"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">mysqld -remove mysql</span><br></pre></td></tr></table></figure>

<p>3.最后删除MySQL目录及相关环境变量。</p>

</div>


  <div class="book-comments">
    




  </div>



<script src="/myblog/js/book-post.js"></script>

        </div>
      </div>
      <div class="column col-2 hide-lg">
        <div class="book-post-info">
  
    <div class="book-post-meta">

  <div class="author">

    <!-- Author image -->
    <div class="author-img">
      
        <figure
          class="avatar avatar-lg"
          data-initial="A"
          style="background-color: #3b4351;">
        </figure>
      
    </div>

    <!-- Author title -->
    <div class="author-title">
      <div>AJHonD</div>
      <div>2023-02-23</div>
    </div>
  </div>

  
    <div class="divider"></div>

    <div class="link">
      

      <a class="tag-none-link" href="/myblog/tags/mysql/" rel="tag">#mysql</a>
    </div>
    
  

  <div class="divider"></div>
</div>
  

  <div class="book-tocbot">
</div>
<div class="book-tocbot-menu">
  <a class="book-toc-expand" onclick="expand_toc()">展开所有</a>
  <a onclick="go_top()">回到顶部</a>
  <a onclick="go_bottom()">转到底部</a>
</div>


<script src="/myblog/js/book-toc.js"></script>

</div>
      </div>
    </div>
  </div>
  
  <a class="off-canvas-overlay" onclick="hide_canvas()"></a>
</div>

</body>
</html>


<script src="/myblog/js/book.js"></script>
